﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using MatchResults.Services;

namespace MatchResults.View
{
    public partial class ResultView : UserControl
    {
        public ResultView()
        {
            
            InitializeComponent();
            int i = 0;
            foreach (ListPickerItem item in cmbDates.Items)
            {
                //17 haziran 2012 pazar
                DateTime date = DateTime.Now.AddDays(-i);
                item.Content = date.Day.ToString() + " " + GetTurkishMounthName(date.Month) + " " + date.Year + " " + GetTurkishDayOfWeek(date.DayOfWeek);
                i++;
            }
        }

        private string GetTurkishDayOfWeek(DayOfWeek dayOfWeek)
        {
            switch (dayOfWeek)
            {
                case DayOfWeek.Friday:
                    return "Cuma";
                case DayOfWeek.Monday:
                    return "Pazartesi";

                case DayOfWeek.Saturday:
                    return "Cumartesi";

                case DayOfWeek.Sunday:
                    return "Pazar";

                case DayOfWeek.Thursday:
                    return "Perşembe";

                case DayOfWeek.Tuesday:
                    return "Salı";

                case DayOfWeek.Wednesday:
                    return "Çarşamba";
                default:
                    return string.Empty;

            }
        }

        private string GetTurkishMounthName(int mounth)
        {
            switch (mounth)
            {
                case 1:
                    return "Ocak";
                case 2:
                    return "Şubat";
                case 3:
                    return "Mart";
                case 4:
                    return "Nisan";
                case 5:
                    return "Mayıs";
                case 6:
                    return "Haziran";
                case 7:
                    return "Temmuz";
                case 8:
                    return "Ağustos";
                case 9:
                    return "Eylül";
                case 10:
                    return "Ekim";
                case 11:
                    return "Kasım";
                case 12:
                    return "Aralık";
                default:
                    return string.Empty;
            }
        }

        private void CmbDatesChange(object sender, SelectionChangedEventArgs e)
        {
            MatchResultService reader = new MatchResultService();
            reader.OnComplete += new EventHandler(reader_OnComplete);
          
            if (prgssLoading != null)
            {
                txtLoading.Visibility = System.Windows.Visibility.Visible;
                prgssLoading.Visibility = System.Windows.Visibility.Visible;
                prgssLoading.IsIndeterminate = true;
                
            }
            reader.GetMessages(messages => grdMatchResult.ItemsSource = messages, (((System.Windows.Controls.ContentControl)(e.AddedItems[0])).Tag.ToString()));
        }

        void reader_OnComplete(object sender, EventArgs e)
        {
            if (prgssLoading != null)
            {
                prgssLoading.IsIndeterminate = false;
                txtLoading.Visibility = System.Windows.Visibility.Collapsed;
                prgssLoading.Visibility = System.Windows.Visibility.Collapsed;
            }
        }


    }
}
